require.config({
    paths: {
        jquery: '../common/js/jquery.min.js',
        bootstrap: "../common/js/bootstrap.min.js",
        "datatables.net": "../common/js/jquery.dataTables.js",
        dataTables: "../common/js/dataTables.bootstrap.min.js",
        content: "../common/js/content.min.js",
        validate: "../common/js/jquery.validate.min.js",
        validate_msg_cn: "../common/js/message-cn.js",
        form: "../common/js/jquery.form.js",
        layer: '../vendor/layer/layer.js',
        json2: '../common/js/json2.js',
        Utils: 'Utils.js'
    },
    shim: {
        "bootstrap": {deps: ["jquery"]},
        "datatables.net": {deps: ["jquery"]},
        "dataTables": {deps: ["jquery", 'bootstrap', 'datatables.net']},
        "validate": {deps: ["jquery"]},
        "content": {deps: ["jquery"]},
        "validate_msg_cn": {deps: ["jquery", "validate"]},
        "form": {deps: ["jquery"]},
        "layer": {deps: ["jquery"]},
        "Utils": {deps: ["jquery", 'json2']}
    }
});
require(['jquery', 'Utils',  'bootstrap','datatables.net', 'dataTables', 'validate', 'validate_msg_cn', 'form', 'layer'],
    function (jQuery, Utils) {
        $ = jQuery;
        var User = {
            varlidator: '',
            form: {
                modify_psw_form : "#modify-psw-form"
            },
            init: function () {
                $(".dataTables-example").DataTable({
                    "paging": true,
                    "searching":true,
                    "info": true,
                    "ordering": true,
                    "language": {
                        "url": "/resources/common/js/zh-cn.json"
                    }
                });
                this.validAndSubmitForm();
                this.handleContactEvents();
            },
            handleContactEvents: function () {

                //新增页面 更新联系人信息
                $("#modify-psw-form").on("click", "#modify-psw", function () {
                    if ($(User.form.modify_psw_form).valid()) {
                        var params = $(User.form.modify_psw_form).serialize();
                        console.log("params : ", params);
                        Utils.ajaxSubmit(Utils.getUrl("/user/modifyPswBy"), params, function (data) {
                            if (data.success == true) {
                                layer.alert("保存密码成功", {icon: 0, title: '修改密码提示'});
                            }
                            if (data.success == false) {
                                layer.alert(data.msg, {icon: 0, title: '修改密码提示'});
                            }
                        });
                    } else {
                        User.varlidator.focusInvalid();
                    }
                });
            },
            validAndSubmitForm: function () {
                //个人账号申请信息
                User.varlidator = $(User.form.modify_psw_form).validate({
                    errorElement: "span",
                    errorClass: "error-block",
                    focusInvalid: true,
                    rules: {
                        oldPsw: {required: true, maxlength: 20},
                        newPsw: {required: true, maxlength: 20},
                        newPswConfirm: {required: true, maxlength: 20,equalTo: "#newPsw"}
                    },
                    messages: {
                        oldPsw: {required: "输入旧密码", maxlength: 20},
                        newPsw: {required: '输入新密码', maxlength: 20},
                        newPswConfirm: {required: '确认新密码', maxlength: 20,equalTo:'两次输入的密码不一致'}
                    }
                });
                /*
                 //邮箱
                 $.validator.addMethod("isEmail", function (value, element) {
                 return this.optional(element) || Utils.isEmail(value);
                 }, "请输入正确的邮箱");*/
            }
        };
        Utils.ajaxFilter();
        User.init();

    }
);